<?php
/* @var $this ApplesController */
/* @var $model Apples */

$this->breadcrumbs=array(
	'Apples'=>array('index'),
	'Manage',
);

if(0==strcmp(Yii::app()->user->name,"admin")){ 
	$this->menu=array(
		array('label'=>'添加测试号码', 'url'=>array('create')),
		array('label'=>'所有号码', 'url'=>array('admin')),
		array('label'=>'在线的号码', 'url'=>array('admin&Apples[stat]=2')),
		array('label'=>'更新统计数据', 'url'=>array('group&save=2')),
		array('label'=>'清理号码', 'url'=>array('check&start=1'),'linkOptions'=>array('class'=>'clean_check'))
	);
}

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#apples-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});

jQuery(document).on('click','.clean_check',function() {
	if(!confirm('是否要清理正在扫描的号码?')) return false;
	return true;
});

$('#selectcity').on('change',function() {
	var url = location.href;
	if (url.indexOf('Apples[province]') > -1){
		url = url.substring(0,url.indexOf('Apples[province]')-1);
	}
	//alert(url);
	location.href=url+'&Apples[province]='+encodeURI($('#selectcity').val());
});
");
?>

<h1>Manage Apples</h1>
 

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

 
<?php
echo CHtml::dropDownList('selectcity','', Globals::province(),array('empty'=>array('all'=>'全国')));

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'apples-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'pager' => array(
        'maxButtonCount'=>13
    ),

	'columns'=>array(
		 
		array(
		'name'=>'appleid',
		'value'=>'0==strcmp(Yii::app()->user->name,\'admin\')?$data->appleid:substr($data->appleid,0,4)."****".substr($data->appleid,8)',
		'type'=>'raw'
		), 
		array(
		'name'=>'city',
		// 'value'=>'date("Y-m-d H:i:s", time()) ."==". ($data->lasttime)',
		'value'=>'$data->province." ".$data->city',
		'type'=>'raw'
		), 
		array(
		'name'=>'stat',
		// 'value'=>'date("Y-m-d H:i:s", time()) ."==". ($data->lasttime)',
		'value'=>'($data->stat==0?"初始化":"").($data->stat==1?"扫描中":"").($data->stat==2?"在线":"").($data->stat==3?"未开通":"").($data->stat==9?"测试号码":"")',
		'type'=>'raw'
		), 
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>
